package com.hxd.otc.module.my.activity;

import android.support.annotation.IdRes;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.widget.FrameLayout;

import com.hxd.otc.R;
import com.hxd.otc.base.BaseActivity;
import com.hxd.otc.common.enums.BankType;
import com.hxd.otc.module.my.contract.AddPayContract;
import com.hxd.otc.module.my.fragment.AddAlipayOrWeiXinFragment;
import com.hxd.otc.module.my.fragment.AddBankCardFragment;
import com.hxd.otc.module.my.fragment.AddOtherPayFragment;
import com.hxd.otc.module.my.presenter.AddPayPresenter;
import com.hxd.otc.widget.TitleBar;

import butterknife.BindView;

import static com.hxd.otc.common.enums.BankType.*;

/**
 * Created by lzy on 2018/6/7 0007.
 * description ${
 * 添加支付界面
 * 1、该Activity将通过Fragment分配管理各种支付方式的添加
 * 2、添加支付方式的标题是通过该Activity来管理
 * }
 */
public class AddPayActivity extends BaseActivity<AddPayPresenter> implements AddPayContract.View {

    public static final String EXTRA_BANK_TYPE = "bank_type";
    @BindView(R.id.title_bar)
    TitleBar mTitleBar;
    @BindView(R.id.fl_container)
    FrameLayout mFlContainer;
    private BankType mBankType;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_add_pay;
    }

    @Override
    protected void initView() {
        mBankType = (BankType) getBundle().getSerializable(EXTRA_BANK_TYPE);
        if (mBankType == null) return;
        mTitleBar.getTitle().setText(String.format(getString(R.string.my_add_card), mBankType.getBankName()));

        Fragment fragment;
        switch (mBankType) {
            case BANK:
                fragment = AddBankCardFragment.getInstance();
                break;
            case ALIPAY:
                fragment = AddAlipayOrWeiXinFragment.getInstance(ALIPAY);
                break;
            case WEXIN:
                fragment = AddAlipayOrWeiXinFragment.getInstance(WEXIN);
                break;
            default:
                fragment = AddOtherPayFragment.getInstance();
                break;
        }
        fragment.setArguments(getBundle());
        replaceFragment(R.id.fl_container, fragment, null);
    }


    @Override
    protected void initData() {

    }

    @Override
    protected void initEvent() {

    }

    @Override
    protected AddPayPresenter createPresenter() {
        return new AddPayPresenter(this);
    }

    public void replaceFragment(@IdRes int containerViewId, Fragment fragment, String tag) {
        FragmentTransaction transaction = getSupportFragmentManager()
                .beginTransaction();
        transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
        transaction.replace(containerViewId, fragment, tag)
                .commit();
    }
}
